package dal

import (
	"crypto/tls"
	"log"

	mysql2 "github.com/go-sql-driver/mysql"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"hertz-nbdemo/biz/dal/query"
)

func InitDal() {
	mysql2.RegisterTLSConfig("tidb", &tls.Config{
		MinVersion: tls.VersionTLS12,
		ServerName: "gateway01.ap-southeast-1.prod.aws.tidbcloud.com",
	})

	// mysql.New(mysql.Config{DSN: "", DSNConfig: &mysql2.Config{}})
	gormdb, err := gorm.Open(mysql.Open("UzD78gpSm67aFia.root:QhyVec0Xoc1lkjNR@tcp(gateway01.ap-southeast-1.prod.aws.tidbcloud.com:4000)/hertz_nb?tls=tidb"), &gorm.Config{
		PrepareStmt:            true,
		SkipDefaultTransaction: true,
	})
	if err != nil {
		log.Fatal(err)
	}
	query.SetDefault(gormdb)
}
